package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.provider.model.dto.watch.BindDmcWatchOldmanDto;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcWatchOldmanService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-24 09:40
 * @Description: the class dmc watch oldman controller
 */
@RestController
@RequestMapping(value = "/watch", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcWatchOldmanController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @Resource
    private DmcWatchOldmanService dmcWatchOldmanService;

    /**
     * 绑定手环 - 老人
     */
    @ValidateAnnotation
    //@LogAnnotation(isSaveResponseData = true, isSaveRequestData = true)
    @RequestMapping(value = "/bindDmcWatchOldman", method = RequestMethod.POST)
    public Wrapper bindDmcWatchOldman(@Validated @RequestBody BindDmcWatchOldmanDto bindDmcWatchOldmanDto,
                                      BindingResult br) {

        Integer result = dmcWatchOldmanService.bindDmcWatchOldman(bindDmcWatchOldmanDto);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

      //  return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 根据设备Id解绑孝心手环 - 老人
     */
   // @LogAnnotation(isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/breakDmcWatchOldmanByDeviceId/{deviceId}", method = RequestMethod.POST)
    public Wrapper breakDmcWatchOldmanByDeviceId(@PathVariable Long deviceId) {

        Integer result = dmcWatchOldmanService.breakDmcWatchOldmanByDeviceId(deviceId);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

}
